<template>
  <div class="login">
    <div class="fromBox">
      <div class="chahua">
        <img :src="chahua" alt="" srcset="" />
      </div>
      <div class="inputBox">
        <div class="formTittle">
          <h3>欢迎来到飞翔</h3>
        </div>
        <el-form
          :model="ruleForm"
          :rules="rules"
          ref="ruleForm"
          label-width="100px"
          class="demo-ruleForm"
        >
          <el-form-item label="" prop="userName">
            <el-input
              v-model="ruleForm.userName"
              prefix-icon="el-icon-mobile-phone"
              placeholder="请输入账号"
            ></el-input>
          </el-form-item>
          <el-form-item label="" prop="pwd">
            <el-input
              type="passworld"
              v-model="ruleForm.pwd"
              prefix-icon="el-icon-unlock"
              placeholder="设置登录密码不少于8位"
            ></el-input>
          </el-form-item>
          <el-form-item label="" prop="pwd">
            <el-input
              type="passworld"
              v-model="ruleForm.pwd"
              prefix-icon="el-icon-unlock"
              placeholder="请确认登录密码"
            ></el-input>
          </el-form-item>
          <el-form-item>
            <el-button class="loginBut" type="primary">下一步</el-button>
          </el-form-item>
          <router-link
            class="register"
            :underline="false"
            to="login"
          >
          &lt;返回登录
          </router-link>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
import chahua from "../../public/images/denglu-chahua_03.png";
import { getLogin } from "../api/Login";
import { setToken } from "../utils/server/cookiejs";
export default {
  data() {
    return {
      chahua: chahua,
      ruleForm: {
        userName: "",
        pwd: "",
      },
      rules: {
        userName: [
          { required: true, message: "请输入用户名", trigger: "blur" },
          { min: 3, max: 8, message: "长度在 3 到 8 个字符", trigger: "blur" },
        ],
        pwd: [{ required: true, message: "请输入密码", trigger: "blur" }],
      },
    };
  },

  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          getLogin(this.ruleForm).then((res) => {
            console.log("返回值", res);
            if (res.code === 200) {
              setToken("token", res.data.token);
              this.$router.push("/");
              console.log(res);
            }
          });
        } else if (res.code === 500) {
          console.log("登陆失败");
          return false;
        } else {
          console.log();
        }
      });
    },
  },
};
</script>

<style lang="less" scoped>
.login {
  width: 100%;
  height: 100vh;
  background: url("../assets/img/bg9.jpg");
  background-size: 100% 100%;
  .fromBox {
    width: 600px;
    height: 500px;
    background-color: white;
    position: absolute;
    left: 50%;
    top: 50%;
    display: flex;
    padding: 0 20px;
    align-items: center;
    border-radius: 10%;
    transform: translate(-50%, -50%);
    .chahua {
      margin-left: 10px;
    }
    .inputBox {
      width: 400px;
      height: 400px;
      .el-form-item {
        width: 75%;
      }
      .loginBut {
        width: 100%;
      }
      .formTittle {
        width: 400px;
        height: 150px;
        display: flex;
        justify-content: center;
        align-items: center;
        h3 {
          font-size: 30px;
          color: #3d8ffd;
          font-weight: 800;
        }
        img {
          margin-right: 10px;
        }
      }
    }
  }
}
.links {
  display: flex;
  justify-content: space-between;
}
.el-link.el-link--primary {
  color: #3dc0fd;
}
.register {
  color: #3dc0fd;
  font-size: 10px;
  margin-left: 25%;
}
</style>